package com.server.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.entity.User;




public class LoginDao extends BasicDao{
	
	
	
	
	public User query(User user){
		String sql="select * from user where user_id="+user.getUserId();
		Connection conn=getConnection();
		PreparedStatement prs=null;
		ResultSet rs=null;
		User reUser=new User();
		try {
			prs = conn.prepareStatement(sql);
			rs=prs.executeQuery(sql);
			
			
			if(rs.next()){
				
				System.out.print(rs.getString("user_id"));
				reUser.setUserId(rs.getString("user_id"));
				if(user.getPass().equals( rs.getString("password"))){
					
					reUser.setPass(rs.getString("password"));
					int r=rs.getInt("role");
					String role=null;
					switch (r) {
					case 1:role="管理员";
						break;
					case 2:role="教师";
					    break;
					case 3:role="学生";
					    break;
					} 
					if(user.getRole().equals(role)){
						reUser.setRole(role);
					}
				}
			
			}
			
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return reUser;
	}
}
